package com.miracle9.game.service;

import com.miracle9.game.bean.Pager;
import com.miracle9.game.dao.*;
import com.miracle9.game.entity.*;
import com.miracle9.game.util.GameParameterAssist;
import com.miracle9.game.util.MyUtil;
import org.apache.mina.core.session.IoSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

@Service("userMailService")
public class UserMailService
        extends BaseService {

    @Autowired
    private UserMailServiceDao userMailServiceDao;
    @Autowired
    private UserServiceDao userServiceDao;
    @Autowired
    private MailServiceDao mailServiceDao;
    @Autowired
    private AdminServiceDao adminServiceDao;
    @Autowired
    private com.miracle9.game.dao.AdminLogServiceDao adminLogServiceDao;
    @Autowired
    private DeskServiceDao deskServiceDao;
    @Autowired
    private FishDeskServiceDao fishDeskServiceDao;
    @Autowired
    private FishKingDB fishKingDB;
    @Autowired
    private LiKuiFishDeskDao liKuiFishDeskDao;
    @Autowired
    private GoldenCicadaFishDeskDao goldenCicadaFishDeskDao;
    @Autowired
    private TianGongDeskDao tianGongDeskDao;
    @Autowired
    private BcbmDeskDao bcbmDeskDao;
    @Autowired
    private GoldSharkDeskDao goldSharkDeskDao;
    @Autowired
    private DragonTigerDeskDao dragonTigerDeskDao;
    @Autowired
    private CardDeskServiceDao cardDeskServiceDao;
    @Autowired
    private com.miracle9.game.dao.BulletFishDeskServiceDao bulletFishDeskServiceDao;
    @Autowired
    private MermaidDeskServiceDao mermaidDeskServiceDao;
    @Autowired
    private LackDeskServiceDao lackDeskServiceDao;
    @Autowired
    private JoyDeskServiceDao joyDeskServiceDao;

    public UserMail[] mailList(IoSession session) {
        Object obj = session.getAttribute("id");
        Integer userId = Integer.valueOf(Integer.parseInt(obj.toString()));
        List<UserMail> mails = this.userMailServiceDao.getByUserIdOrderByDatetime(userId);
        for (UserMail m : mails) {
            m.setContent("");
        }
        return (UserMail[]) mails.toArray(new UserMail[0]);
    }

    public boolean deleteMail(String ids, IoSession session) {
        Object obj = session.getAttribute("id");
        Integer userId = Integer.valueOf(Integer.parseInt(obj.toString()));
        try {
            this.userMailServiceDao.deleteByIds(ids, userId);
        } catch (Exception e) {
            return false;
        }
        return true;
    }

    public Map<String, Object> getMailContent(int id, IoSession session) {
        Map result = new HashMap();
        UserMail mail = (UserMail) this.userMailServiceDao.getByUserIdOrderByDatetime(Integer.valueOf(id));
        if (mail == null) {
            result.put("flag", Boolean.valueOf(false));
            return result;
        }
        result.put("flag", Boolean.valueOf(true));
        result.put("sender", mail.getSender());
        result.put("datetime", mail.getDatetime());
        result.put("content", mail.getContent());
        this.userMailServiceDao.updateStatus_1ById(Integer.valueOf(id), Integer.valueOf(mail.getUserId()));
        return result;
    }

    public Pager getMailList(Pager pager, IoSession session) {
        if ((pager.getOrder() == "") && (pager.getOrderBy() == "")) {
            pager.setOrderBy("datetime");
            pager.setOrder("desc");
        }
        pager = this.mailServiceDao.getPager(pager);
        Object[] os = pager.getList();
        Object[] array;
        int length = (array = os).length;
        for (int i = 0; i < length; i++) {
            Object o = array[i];
            Mail m = (Mail) o;
            m.setContent(m.getContent().replaceAll("(\r\n|\r|\n|\n\r)", ""));
        }
        return pager;
    }

    public void addUserMail(Admin admin, String datetime, Mail mail) {
        List<User> users = this.userServiceDao.q_CreateSqlList("from User", new Object[0]);
        for (User u : users) {
            UserMail um = new UserMail(mail.getId(), mail.getTitle(), mail.getContent(), datetime,
                    admin.getUsername(), 0, u.getId(), u.getUsername());
            this.userMailServiceDao.saveReturnInteger(um);
            IoSession s = (IoSession) com.miracle9.game.util.GameParameterAssist.ba.get(Integer.valueOf(u.getId()));
            if (s != null) {
                com.miracle9.game.server.message.MessageSend.q.notifyAllOperating(new com.miracle9.game.server.message.StorageMethodEntity(s,
                        "newUserMail", new Object[0]));
            }
        }
    }

    public Map<String, Object> sendMail(final Mail mail, IoSession session) {
        Map result = new HashMap();
        List<User> sendToUsers = null;
        int nJoyDeskCount;
        if (mail.getRangeType() == 3) {
            try {
                int deskId = Integer.valueOf(mail.getIds()).intValue();
                int deskCount = this.deskServiceDao.q_CreateSqlInt("select count(*) from Desk where id=?",
                        new Object[]{Integer.valueOf(deskId)});
                int fishDeskCount = this.deskServiceDao.q_CreateSqlInt(
                        "select count(*) from FishDesk where id=?", new Object[]{Integer.valueOf(deskId)});
                int cardDeskCount = this.deskServiceDao.q_CreateSqlInt(
                        "select count(*) from CardDesk where id=?", new Object[]{Integer.valueOf(deskId)});
                int bulletDeskCount = this.deskServiceDao.q_CreateSqlInt(
                        "select count(*) from BulletFishDesk where id=?", new Object[]{Integer.valueOf(deskId)});
                int mermaidDeskCount = this.deskServiceDao.q_CreateSqlInt(
                        "select count(*) from MermaidDesk where id=?", new Object[]{Integer.valueOf(deskId)});
                int lackDeskCount = this.deskServiceDao.q_CreateSqlInt(
                        "select count(*) from LackDesk where id=?", new Object[]{Integer.valueOf(deskId)});
                nJoyDeskCount = this.deskServiceDao.q_CreateSqlInt(
                        "select count(*) from JoyDesk where id=?", new Object[]{Integer.valueOf(deskId)});
                if ((deskCount > 0) || (fishDeskCount > 0) || (cardDeskCount > 0) || (bulletDeskCount > 0) ||
                        (mermaidDeskCount > 0) || (lackDeskCount > 0) || (nJoyDeskCount > 0)) {
                    //break label455;
                    return result;
                }
                result.put("success", Boolean.valueOf(false));
                result.put("message", MyUtil.getProperties(Integer.valueOf(resultInt(session)),
                        "deskIdNotExist"));
                return result;
            } catch (Exception e) {
                result.put("success", Boolean.valueOf(false));
                result.put("message",
                        MyUtil.getProperties(Integer.valueOf(resultInt(session)), "deskIdNotExist"));
                return result;
            }
        } else if (mail.getRangeType() == 4) {
            sendToUsers = new ArrayList();
            String[] usernames = mail.getIds().split(";");
            String[] array;
            int length = (array = usernames).length;
            for (int i = 0; i < length; i++) {
                String uname = array[i];
                User u = (User) this.userServiceDao.q_CreateSqlFilter("from User where username=?",
                        new Object[]{uname});
                if (u == null) {
                    result.put("success", Boolean.valueOf(false));
                    result.put("message", MyUtil.getProperties(Integer.valueOf(resultInt(session)),
                            "usernameNotExist"));
                    return result;
                }
                sendToUsers.add(u);
            }
        }
        //label455:
        Integer adminId = Integer.valueOf(session.getAttribute("id").toString());
        final Admin admin = (Admin) this.adminServiceDao.getById(adminId);
        final String datetime = MyUtil.dateFormatYMD_HMS_Sting(new Date());
        mail.setDatetime(datetime);
        mail.setTitle(mail.getTitle().replaceAll("(\r\n|\r|\n|\n\r)", ""));
        mail.setAdmin(admin.getUsername());
        this.mailServiceDao.saveReturnInteger(mail);
        String content = null;
        String contentEn = null;
        if (mail.getRangeType() == 0) {
            content = "发送了邮件，目标全服";
            contentEn = "Send a mail to all";
            new Thread() {
                public void run() {
                    UserMailService userMailService = (UserMailService)
                            com.miracle9.game.util.MyApplicationContext.a().getBean("userMailService");
                    userMailService.addUserMail(admin, datetime, mail);
                }
            }.start();
        } else {
            List<FishKingDesk> fishKingDesks;
            Object mds;
            if (mail.getRangeType() == 1) {
                content = "发送了邮件，目标新手练习厅所有桌";
                contentEn = "Send a mail to all tables in Practice room";
                List<Desk> desks = this.deskServiceDao.getAllDesk();
                List<User> users;
                UserMail um;
                for (Desk d : desks) {
                    if (d.getRoomId() != 2) {
                        users = (List) com.miracle9.game.util.GameParameterAssist.bm.get(Integer.valueOf(d.getId()));
                        if (users != null) {
                            for (User u2 : users) {
                                um = new UserMail(mail.getId(), mail.getTitle(), mail.getContent(), datetime,
                                        admin.getUsername(), 0, u2.getId(), u2.getUsername());
                                this.userMailServiceDao.saveReturnInteger(um);
                            }
                        }
                    }
                }
                List<FishDesk> fishDesks = this.fishDeskServiceDao.getFishDesks();
                for (FishDesk d2 : fishDesks) {
                    if (d2.getRoomId() != 2) {
                        users = (List) com.miracle9.game.util.GameParameterAssist.bn.get(Integer.valueOf(d2.getId()));
                        if (users != null) {
                            for (User u3 : users) {
                                um = new UserMail(mail.getId(), mail.getTitle(), mail.getContent(), datetime,
                                        admin.getUsername(), 0, u3.getId(), u3.getUsername());
                                this.userMailServiceDao.saveReturnInteger(um);
                            }
                        }
                    }
                }
                fishKingDesks = this.fishKingDB.getFishKingDeskList();
                for (FishKingDesk d2 : fishKingDesks) {
                    if (d2.getRoomId() != 2) {
                        users = (List) com.miracle9.game.util.GameParameterAssist.bn_king.get(Integer.valueOf(d2.getId()));
                        if (users != null) {
                            for (int i = 0; i < ((List) users).size(); i++) {
                                um = new UserMail(mail.getId(), mail.getTitle(), mail.getContent(), datetime,
                                        admin.getUsername(), 0, ((User) ((List) users).get(i)).getId(), ((User) ((List) users).get(i)).getUsername());
                                this.userMailServiceDao.saveReturnInteger(um);
                            }
                        }
                    }
                }
                List<LiKuiFishDesk> liKuiFishDeskList = this.liKuiFishDeskDao.getLiKuiFishDeskList();
                for (LiKuiFishDesk d2 : liKuiFishDeskList) {
                    if (d2.getRoomId() != 2) {
                        users = GameParameterAssist.likuiFishUserList.get(Integer.valueOf(d2.getId()));
                        if (users != null) {
                            for (int i = 0; i < users.size(); i++) {
                                um = new UserMail(mail.getId(), mail.getTitle(), mail.getContent(), datetime,
                                        admin.getUsername(), 0, users.get(i).getId(), users.get(i).getUsername());
                                this.userMailServiceDao.saveReturnInteger(um);
                            }
                        }
                    }
                }
                List<GoldenCicadaFishDesk> goldenCicadaFishDesksList = this.goldenCicadaFishDeskDao.getGoldenCicadaFishDeskList();
                for (GoldenCicadaFishDesk d2 : goldenCicadaFishDesksList) {
                    if (d2.getRoomId() != 2) {
                        users = GameParameterAssist.goldenFishUserList.get(Integer.valueOf(d2.getId()));
                        if (users != null) {
                            for (int i = 0; i < users.size(); i++) {
                                um = new UserMail(mail.getId(), mail.getTitle(), mail.getContent(), datetime,
                                        admin.getUsername(), 0, users.get(i).getId(), users.get(i).getUsername());
                                this.userMailServiceDao.saveReturnInteger(um);
                            }
                        }
                    }
                }
                List<TianGongDesk> tianGongDeskList = this.tianGongDeskDao.getTianGongDeskList();
                for (TianGongDesk d2 : tianGongDeskList) {
                    if (d2.getRoomId() != 2) {
                        users = GameParameterAssist.tgUserList.get(Integer.valueOf(d2.getId()));
                        if (users != null) {
                            for (int i = 0; i < users.size(); i++) {
                                um = new UserMail(mail.getId(), mail.getTitle(), mail.getContent(), datetime,
                                        admin.getUsername(), 0, users.get(i).getId(), users.get(i).getUsername());
                                this.userMailServiceDao.saveReturnInteger(um);
                            }
                        }
                    }
                }
                List<BcbmDesk> bcbmDeskList = this.bcbmDeskDao.getBcbmDeskList();
                for (BcbmDesk d2 : bcbmDeskList) {
                    if (d2.getRoomId() != 2) {
                        users = GameParameterAssist.bcbmUserList.get(Integer.valueOf(d2.getId()));
                        if (users != null) {
                            for (int i = 0; i < users.size(); i++) {
                                um = new UserMail(mail.getId(), mail.getTitle(), mail.getContent(), datetime,
                                        admin.getUsername(), 0, users.get(i).getId(), users.get(i).getUsername());
                                this.userMailServiceDao.saveReturnInteger(um);
                            }
                        }
                    }
                }
                List<GoldSharkDesk> goldSharkDeskList = this.goldSharkDeskDao.getAllDesk();
                for (GoldSharkDesk d2 : goldSharkDeskList) {
                    if (d2.getRoomId() != 2) {
                        users = GameParameterAssist.goldSharkUserList.get(Integer.valueOf(d2.getId()));
                        if (users != null) {
                            for (int i = 0; i < users.size(); i++) {
                                um = new UserMail(mail.getId(), mail.getTitle(), mail.getContent(), datetime,
                                        admin.getUsername(), 0, users.get(i).getId(), users.get(i).getUsername());
                                this.userMailServiceDao.saveReturnInteger(um);
                            }
                        }
                    }
                }
                List<DragonTigerDesk> dragonTigerDeskList = this.dragonTigerDeskDao.getAllDesk();
                for (DragonTigerDesk d2 : dragonTigerDeskList) {
                    if (d2.getRoomId() != 2) {
                        users = GameParameterAssist.lhdUserList.get(Integer.valueOf(d2.getId()));
                        if (users != null) {
                            for (int i = 0; i < users.size(); i++) {
                                um = new UserMail(mail.getId(), mail.getTitle(), mail.getContent(), datetime,
                                        admin.getUsername(), 0, users.get(i).getId(), users.get(i).getUsername());
                                this.userMailServiceDao.saveReturnInteger(um);
                            }
                        }
                    }
                }
                List<CardDesk> cardDesks = this.cardDeskServiceDao.getCardDesks();
                for (users = (List<User>) cardDesks.iterator(); ((Iterator) users).hasNext(); ) {
                    CardDesk d3 = (CardDesk) ((Iterator) users).next();
                    if (d3.getRoomId() != 2) {
                        users = (List) com.miracle9.game.util.GameParameterAssist.bo.get(Integer.valueOf(d3.getId()));
                        if (users != null) {
                            for (User u3 : users) {
                                um = new UserMail(mail.getId(), mail.getTitle(), mail.getContent(), datetime,
                                        admin.getUsername(), 0, u3.getId(), u3.getUsername());
                                this.userMailServiceDao.saveReturnInteger(um);
                            }
                        }
                    }
                }
                List<BulletFishDesk> bulletFishDesks = this.bulletFishDeskServiceDao.gteBulletFishDesks();
                for (BulletFishDesk d4 : bulletFishDesks) {
                    if (d4.getRoomId() != 2) {
                        users = (List) com.miracle9.game.util.GameParameterAssist.bp.get(Integer.valueOf(d4.getId()));
                        if (users != null) {
                            for (User u4 : users) {
                                um = new UserMail(mail.getId(), mail.getTitle(), mail.getContent(), datetime,
                                        admin.getUsername(), 0, u4.getId(), u4.getUsername());
                                this.userMailServiceDao.saveReturnInteger(um);
                            }
                        }
                    }
                }
                mds = this.mermaidDeskServiceDao.getMermaidDesks();
        /*for (MermaidDesk d5 : (List)mds) {
          if (d5.getRoomId() != 2)
          {
            users = (List)com.miracle9.game.util.GameParameterAssist.bq.get(Integer.valueOf(d5.getId()));
            if (users != null) {
              for (User u5 : users)
              {
                um = new UserMail(mail.getId(), mail.getTitle(), mail.getContent(), datetime, 
                  admin.getUsername(), 0, u5.getId(), u5.getUsername());
                this.userMailServiceDao.IIIIlIlIIIIlIIlI(um);
              }
            }
          }
        }*/
                for (int i = 0; i < ((List) mds).size(); i++) {
                    if (((MermaidDesk) ((List) mds).get(i)).getRoomId() != 2) {
                        users = (List) com.miracle9.game.util.GameParameterAssist.bq.get(Integer.valueOf(((MermaidDesk) ((List) mds).get(i)).getId()));
                        if (users != null) {
                            for (User u5 : users) {
                                um = new UserMail(mail.getId(), mail.getTitle(), mail.getContent(), datetime,
                                        admin.getUsername(), 0, u5.getId(), u5.getUsername());
                                this.userMailServiceDao.saveReturnInteger(um);
                            }
                        }
                    }
                }
                List<LackDesk> lackDesks = this.lackDeskServiceDao.getLackDesks();
                for (LackDesk d6 : lackDesks) {
                    if (d6.getRoomId() != 2) {
                        users = (List) com.miracle9.game.util.GameParameterAssist.aO.get(Integer.valueOf(d6.getId()));
                        if (users != null) {
                            for (User u5 : users) {
                                um = new UserMail(mail.getId(), mail.getTitle(), mail.getContent(), datetime,
                                        admin.getUsername(), 0, u5.getId(), u5.getUsername());
                                this.userMailServiceDao.saveReturnInteger(um);
                            }
                        }
                    }
                }
                List<JoyDesk> joyDesks = this.joyDeskServiceDao.getJoyDesks();
                for (JoyDesk joyDesk : joyDesks) {
                    if (joyDesk.getRoomId() != 2) {
                        users = (List) com.miracle9.game.util.GameParameterAssist.aO.get(Integer.valueOf(joyDesk.getId()));
                        if (users != null) {
                            for (User u6 : users) {
                                um = new UserMail(mail.getId(), mail.getTitle(), mail.getContent(), datetime,
                                        admin.getUsername(), 0, u6.getId(), u6.getUsername());
                                this.userMailServiceDao.saveReturnInteger(um);
                            }
                        }
                    }
                }
            } else {
                List<CardDesk> cardDesks;
                if (mail.getRangeType() == 2) {
                    content = "发送了邮件，目标欢乐竞技厅所有桌";
                    contentEn = "Send a mail to all tables in Compete room";
                    List<Desk> desks2 = this.deskServiceDao.getAllDesk();
                    List<User> users2;
                    UserMail um2;
                    for (Desk d7 : desks2) {
                        if (d7.getRoomId() != 1) {
                            users2 = (List) com.miracle9.game.util.GameParameterAssist.bm.get(Integer.valueOf(d7.getId()));
                            if (users2 != null) {
                                for (mds = users2.iterator(); ((Iterator) mds).hasNext(); ) {
                                    User u3 = (User) ((Iterator) mds).next();
                                    um2 = new UserMail(mail.getId(), mail.getTitle(), mail.getContent(), datetime,
                                            admin.getUsername(), 0, u3.getId(), u3.getUsername());
                                    this.userMailServiceDao.saveReturnInteger(um2);
                                }
                            }
                        }
                    }
                    List<FishDesk> fishDesks2 = this.fishDeskServiceDao.getFishDesks();
                    for (FishDesk d8 : fishDesks2) {
                        if (d8.getRoomId() != 1) {
                            users2 = (List) com.miracle9.game.util.GameParameterAssist.bn.get(Integer.valueOf(d8.getId()));
                            if (users2 != null) {
                                for (User u4 : users2) {
                                    um2 = new UserMail(mail.getId(), mail.getTitle(), mail.getContent(), datetime,
                                            admin.getUsername(), 0, u4.getId(), u4.getUsername());
                                    this.userMailServiceDao.saveReturnInteger(um2);
                                }
                            }
                        }
                    }
                    fishKingDesks = this.fishKingDB.getFishKingDeskList();
                    UserMail um;
                    for (FishKingDesk d2 : fishKingDesks) {
                        if (d2.getRoomId() != 2) {
                            List users = (List) com.miracle9.game.util.GameParameterAssist.bn_king.get(Integer.valueOf(d2.getId()));
                            if (users != null) {
                /*for (User u3 : (List)users)
                {
                  um = new UserMail(mail.getId(), mail.getTitle(), mail.getContent(), datetime, 
                    admin.getUsername(), 0, u3.getId(), u3.getUsername());
                  this.userMailServiceDao.IIIIlIlIIIIlIIlI(um);
                }*/
                                for (int i = 0; i < ((List) users).size(); i++) {
                                    um = new UserMail(mail.getId(), mail.getTitle(), mail.getContent(), datetime,
                                            admin.getUsername(), 0, ((User) ((List) users).get(i)).getId(), ((User) ((List) users).get(i)).getUsername());
                                    this.userMailServiceDao.saveReturnInteger(um);
                                }
                            }
                        }
                    }
                    cardDesks = this.cardDeskServiceDao.getCardDesks();
                    for (Object users = cardDesks.iterator(); ((Iterator) users).hasNext(); ) {
                        CardDesk d9 = (CardDesk) ((Iterator) users).next();
                        if (d9.getRoomId() != 1) {
                            users2 = (List) com.miracle9.game.util.GameParameterAssist.bo.get(Integer.valueOf(d9.getId()));
                            if (users2 != null) {
                                for (User u4 : users2) {
                                    um2 = new UserMail(mail.getId(), mail.getTitle(), mail.getContent(), datetime,
                                            admin.getUsername(), 0, u4.getId(), u4.getUsername());
                                    this.userMailServiceDao.saveReturnInteger(um2);
                                }
                            }
                        }
                    }
                    List<BulletFishDesk> bfs = this.bulletFishDeskServiceDao.gteBulletFishDesks();
                    for (BulletFishDesk d4 : bfs) {
                        if (d4.getRoomId() != 1) {
                            users2 = (List) com.miracle9.game.util.GameParameterAssist.bp.get(Integer.valueOf(d4.getId()));
                            if (users2 != null) {
                                for (User u4 : users2) {
                                    um2 = new UserMail(mail.getId(), mail.getTitle(), mail.getContent(), datetime,
                                            admin.getUsername(), 0, u4.getId(), u4.getUsername());
                                    this.userMailServiceDao.saveReturnInteger(um2);
                                }
                            }
                        }
                    }
                    mds = this.mermaidDeskServiceDao.getMermaidDesks();
          /*for (MermaidDesk d5 : (List)mds) {
            if (d5.getRoomId() != 1)
            {
              users2 = (List)com.miracle9.game.util.GameParameterAssist.bq.get(Integer.valueOf(d5.getId()));
              if (users2 != null) {
                for (User u5 : users2)
                {
                  um2 = new UserMail(mail.getId(), mail.getTitle(), mail.getContent(), datetime, 
                    admin.getUsername(), 0, u5.getId(), u5.getUsername());
                  this.userMailServiceDao.IIIIlIlIIIIlIIlI(um2);
                }
              }
            }
          }*/
                    for (int i = 0; i < ((List) mds).size(); i++) {
                        if (((MermaidDesk) ((List) mds).get(i)).getRoomId() != 1) {
                            users2 = (List) com.miracle9.game.util.GameParameterAssist.bq.get(Integer.valueOf(((MermaidDesk) ((List) mds).get(i)).getId()));
                            if (users2 != null) {
                                for (User u5 : users2) {
                                    um2 = new UserMail(mail.getId(), mail.getTitle(), mail.getContent(), datetime,
                                            admin.getUsername(), 0, u5.getId(), u5.getUsername());
                                    this.userMailServiceDao.saveReturnInteger(um2);
                                }
                            }
                        }
                    }
                    List<LackDesk> lackDesks = this.lackDeskServiceDao.getLackDesks();
                    for (LackDesk d6 : lackDesks) {
                        if (d6.getRoomId() != 1) {
                            users2 = (List) com.miracle9.game.util.GameParameterAssist.aO.get(Integer.valueOf(d6.getId()));
                            if (users2 != null) {
                                for (User u5 : users2) {
                                    um2 = new UserMail(mail.getId(), mail.getTitle(), mail.getContent(), datetime,
                                            admin.getUsername(), 0, u5.getId(), u5.getUsername());
                                    this.userMailServiceDao.saveReturnInteger(um2);
                                }
                            }
                        }
                    }
                    List<JoyDesk> joyDesks = this.joyDeskServiceDao.getJoyDesks();
                    for (JoyDesk joyDesk : joyDesks) {
                        if (joyDesk.getRoomId() != 1) {
                            users2 = (List) com.miracle9.game.util.GameParameterAssist.aQ.get(Integer.valueOf(joyDesk.getId()));
                            if (users2 != null) {
                                for (User u6 : users2) {
                                    um2 = new UserMail(mail.getId(), mail.getTitle(), mail.getContent(), datetime,
                                            admin.getUsername(), 0, u6.getId(), u6.getUsername());
                                    this.userMailServiceDao.saveReturnInteger(um2);
                                }
                            }
                        }
                    }
                } else {
                    List<User> users;
                    if (mail.getRangeType() == 3) {
                        content = "发送了邮件，目标桌ID" + mail.getIds();
                        contentEn = "Send a mail to Table ID:" + mail.getIds();
                        Integer deskId2 = Integer.valueOf(mail.getIds());
                        users = (List) com.miracle9.game.util.GameParameterAssist.bm.get(deskId2);
                        if (users != null) {
                            for (User u7 : users) {
                                UserMail um3 = new UserMail(mail.getId(), mail.getTitle(), mail.getContent(), datetime,
                                        admin.getUsername(), 0, u7.getId(), u7.getUsername());
                                this.userMailServiceDao.saveReturnInteger(um3);
                            }
                        }
                        users = (List) com.miracle9.game.util.GameParameterAssist.bn.get(deskId2);
                        if (users != null) {
                            for (User u7 : users) {
                                UserMail um3 = new UserMail(mail.getId(), mail.getTitle(), mail.getContent(), datetime,
                                        admin.getUsername(), 0, u7.getId(), u7.getUsername());
                                this.userMailServiceDao.saveReturnInteger(um3);
                            }
                        }
                        users = (List) com.miracle9.game.util.GameParameterAssist.bn_king.get(deskId2);
                        if (users != null) {
                            for (User u7 : users) {
                                UserMail um3 = new UserMail(mail.getId(), mail.getTitle(), mail.getContent(), datetime,
                                        admin.getUsername(), 0, u7.getId(), u7.getUsername());
                                this.userMailServiceDao.saveReturnInteger(um3);
                            }
                        }
                        users = (List) com.miracle9.game.util.GameParameterAssist.bo.get(deskId2);
                        if (users != null) {
                            for (User u7 : users) {
                                UserMail um3 = new UserMail(mail.getId(), mail.getTitle(), mail.getContent(), datetime,
                                        admin.getUsername(), 0, u7.getId(), u7.getUsername());
                                this.userMailServiceDao.saveReturnInteger(um3);
                            }
                        }
                        users = (List) com.miracle9.game.util.GameParameterAssist.bp.get(deskId2);
                        if (users != null) {
                            for (User u7 : users) {
                                UserMail um3 = new UserMail(mail.getId(), mail.getTitle(), mail.getContent(), datetime,
                                        admin.getUsername(), 0, u7.getId(), u7.getUsername());
                                this.userMailServiceDao.saveReturnInteger(um3);
                            }
                        }
                        users = (List) com.miracle9.game.util.GameParameterAssist.bq.get(deskId2);
                        if (users != null) {
                            for (User u7 : users) {
                                UserMail um3 = new UserMail(mail.getId(), mail.getTitle(), mail.getContent(), datetime,
                                        admin.getUsername(), 0, u7.getId(), u7.getUsername());
                                this.userMailServiceDao.saveReturnInteger(um3);
                            }
                        }
                        users = (List) com.miracle9.game.util.GameParameterAssist.aO.get(deskId2);
                        if (users != null) {
                            for (User u7 : users) {
                                UserMail um3 = new UserMail(mail.getId(), mail.getTitle(), mail.getContent(), datetime,
                                        admin.getUsername(), 0, u7.getId(), u7.getUsername());
                                this.userMailServiceDao.saveReturnInteger(um3);
                            }
                        }
                        users = (List) com.miracle9.game.util.GameParameterAssist.aQ.get(deskId2);
                        if (users != null) {
                            for (User u7 : users) {
                                UserMail um3 = new UserMail(mail.getId(), mail.getTitle(), mail.getContent(), datetime,
                                        admin.getUsername(), 0, u7.getId(), u7.getUsername());
                                this.userMailServiceDao.saveReturnInteger(um3);
                            }
                        }
                    } else if (mail.getRangeType() == 4) {
                        content = "发送了邮件，目标会员账号" + mail.getIds();
                        contentEn = "Send a mail to member ID:" + mail.getIds();
                        for (User u8 : sendToUsers) {
                            UserMail um4 = new UserMail(mail.getId(), mail.getTitle(), mail.getContent(), datetime,
                                    admin.getUsername(), 0, u8.getId(), u8.getUsername());
                            this.userMailServiceDao.saveReturnInteger(um4);
                            if (com.miracle9.game.util.GameParameterAssist.ba.containsKey(Integer.valueOf(u8.getId()))) {
                                com.miracle9.game.server.message.MessageSend.q.notifyAllOperating(new com.miracle9.game.server.message.StorageMethodEntity(
                                        (IoSession) com.miracle9.game.util.GameParameterAssist.ba.get(Integer.valueOf(u8.getId())),
                                        "newUserMail", new Object[0]));
                            }
                        }
                    }
                }
            }
        }
        AdminLog adminLog = new AdminLog(admin.getUsername(), content, 2, admin.getType(), contentEn);
        this.adminLogServiceDao.addAdminLog(adminLog);
        result.put("success", true);
        return result;
    }

    public Map<String, Object> deleteMail(int id, IoSession session) {
        Map result = new HashMap();
        try {
            this.mailServiceDao.deleteById(Integer.valueOf(id));
            result.put("success", Boolean.valueOf(true));
            result.put("message", "");
            List<UserMail> umails = this.userMailServiceDao.getByMailId(id);
            for (UserMail m : umails) {
                this.userMailServiceDao.updateStatus_1ById(Integer.valueOf(m.getId()), Integer.valueOf(m.getUserId()));
            }
        } catch (Exception e) {
            result.put("success", Boolean.valueOf(true));
            result.put("message", "");
        }
        int adminId = ((Integer) session.getAttribute("id")).intValue();
        Admin admin = (Admin) this.adminServiceDao.getById(Integer.valueOf(adminId));
        AdminLog adminLog = new AdminLog(admin.getUsername(), "删除了邮件", 2, admin.getType(), "Delete a mail");
        this.adminLogServiceDao.addAdminLog(adminLog);
        return result;
    }

    public void deletePastMail(String date) {
        this.userMailServiceDao.deletePastMail(date);
    }

}
